package com.sskj.zixun.ui.activity;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bulong.rudeness.RudenessScreenHelper;
import com.scwang.smartrefresh.header.MaterialHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.adapter.ItemClickSupport;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.mvchelper.ModelRx2DataSource;
import com.sskj.zixun.R;
import com.sskj.zixun.R2;
import com.sskj.zixun.bean.NoticeList;
import com.sskj.zixun.presenter.ZixunFragmentPresenter;
import com.sskj.lib.adapter.BaseAdapter;
import com.sskj.lib.adapter.ViewHolder;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import io.reactivex.Flowable;

/**
 * DESC: (类描述)  个人中心--公告列表
 * Created by hqf on 2018/11/16 15:31
 * updateName:(修改人名称)
 * updateTime:(修改时间)
 * updateDesc:(修改内容)
 */
@Route(path = RConfig.GONGGAO_ACTIVITY_MAIN)//公告
public class GongGaoActivity extends BaseActivity<ZixunFragmentPresenter> {
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;

    @Override
    protected int getLayoutResId() {
        return R.layout.zixun_activity_gong_gao;
    }

    @Override
    public ZixunFragmentPresenter getPresenter() {
        return new ZixunFragmentPresenter();
    }

    @Override
    public void initView() {
        setTitle(App.INSTANCE.getString(R.string.zixunGongGaoActivity0));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setFirstDraw(false)
                .setLastDraw(false)
                .setSecondToLastDraw(false)
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.zixun_525))
                .setLeftPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 30))
                .setRightPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 30)));
        SlimAdapter<NoticeList> slimAdapter = SlimAdapter.create().register(R.layout.zixun_recycler_item_notice, new SlimInjector<NoticeList>() {
            @Override
            public void onInject(NoticeList data, IViewInjector injector, List payloads) {
                injector.text(R.id.notice_title, data.getTitle())
                        .text(R.id.notice_time, data.getCreate_time());
            }
        }).attachTo(recyclerView).updateData(new ArrayList());
        ItemClickSupport.addTo(recyclerView)
                .setOnItemClickListener((recyclerView1, position, v) -> {
                    ARouter.getInstance().build(RConfig.GONGGAO_DETAIL)
                            .withString("noticeId", slimAdapter.getDataItem(position).getId())
                            .navigation();
                });
        ModelRx2DataSource<NoticeList> dataSource = new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<NoticeList>)
                page -> mPresenter.getData(page), 20);
        MVCCoolHelper<List<NoticeList>> mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();
    }


}
